package com.bp.hearthealth.pulse.lnapps.bp_db.bp_heartrate

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query

@Dao
interface BpHeartRateDao {
    //事务，关联user表
//    @Transaction
//    @Query("SELECT * FROM user WHERE id = :userId")
//    fun getUserWithHeartRates(userId: String): List<UserWithHeartRates>

    @Query("SELECT * FROM heart_rate_monitor")
    suspend fun getAllHeartRates(): List<BpHeartRateBean>

//    @Query("SELECT * FROM heart_rate_monitor WHERE userId = :userId")
//    suspend fun getHeartRatesListByUserId(userId: String): List<HeartRateBean>

    @Query("SELECT * FROM heart_rate_monitor WHERE userId = :userId ORDER BY date DESC")
    suspend fun getHeartRatesListByUserId(userId: String): List<BpHeartRateBean>


    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertHeartRateList(heartRateList: List<BpHeartRateBean>): List<Long>

    @Query("UPDATE heart_rate_monitor SET unlocked = :unlocked WHERE id = :id")
    suspend fun updateUnlocked(id: Long, unlocked: Boolean):Int

    @Query("DELETE FROM heart_rate_monitor WHERE id = :id")
    suspend fun deleteHeartRateById(id: Long): Int

    @Query("SELECT number FROM heart_rate_monitor WHERE id = :id")
    suspend fun inquireNum(id: Long): Int

    @Query("SELECT * FROM heart_rate_monitor WHERE id = :id LIMIT 1")
    suspend fun getHeartRateBeanById(id: Long): BpHeartRateBean

}
